package common

import (
	"encoding/json"
	"net/http"
)

const (
	Appcode = "fbe677e7f7664ee8aac2a6efa62b515c"
	url     = "http://eid.shumaidata.com/eid/check"
)

func Real(realname string, idcode string) string {
	payload := url + "?idcard=" + idcode + "&name=" + realname
	client := &http.Client{}
	req, err := http.NewRequest("POST", payload, nil)
	if err != nil {
		return err.Error()
	}
	req.Header.Set("Authorization", "APPCODE "+Appcode)
	res, err := client.Do(req)
	defer res.Body.Close()
	if err != nil {
		return err.Error()
	}

	m := map[string]interface{}{}
	json.NewDecoder(res.Body).Decode(&m)
	f, _ := m["result"].(map[string]interface{})
	return f["description"].(string)
}
